package com.maybach.core.flow.handler;

import com.maybach.common.model.UserDO;
import com.maybach.common.po.PersonCertificatePO;
import com.maybach.core.manager.UserManager;
import com.maybach.dubbo.api.enums.AuditStatusEnum;
import com.maybach.util.AssertUtil;
import com.maybach.util.ImgUrlUtil;
import com.maybach.workflow.common.api.IFlowHandler;
import com.maybach.workflow.common.api.WorkFlowContext;
import com.maybach.workflow.common.api.enums.WFContextKeyEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by houenxun on 16/1/28.
 *
 * 完成个人信息认证进行后续操作，将身份证等个人信息拷贝的个人表中
 */
@Component
public class FinishPersonCertificate  extends FinishSimpleFlow implements IFlowHandler{
    @Autowired
    protected  UserManager userManager;

    @Override
    public void handle(WorkFlowContext context) {
        super.handle(context);
        PersonCertificatePO certificatePO = (PersonCertificatePO)context.getBizData().get(WFContextKeyEnum.flowApplyContent.name());
        AssertUtil.notNull(certificatePO, "PersonCertificatePO by flowId="+context.getThisFlow().getId());
        UserDO userDO = userManager.selectByPrimaryKey(certificatePO.getUserId());
        AssertUtil.notNull(certificatePO, "userDO by userId="+certificatePO.getUserId());
        userDO.setRealName(certificatePO.getRealName());
        userDO.setCertNo(certificatePO.getCertNo());
        userDO.setVisitingCardImgs(ImgUrlUtil.mergeList(certificatePO.getVisitingCardImgs()));
        userDO.setCertImgs(ImgUrlUtil.mergeList(certificatePO.getCertImgs()));
        userDO.setIsVerify(AuditStatusEnum.end.getStatus());
        userManager.updateByPrimaryKeySelective(userDO);

    }

    @Override
    protected String getHandlerKey() {
        return "person";
    }
}
